package com.wl.cms.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wl.cms.entity.CrmBanner;
import com.wl.cms.service.CrmBannerService;
import com.wl.connonutils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 首页banner表 前端控制器
 * </p>
 *
 * @author wl
 * @since 2021-09-02
 */
@RestController
@RequestMapping("/cms/bannerAdmin")
public class CrmBannerController {

    @Autowired
    private CrmBannerService crmBannerService;

    @GetMapping("pageBanner/{page}/{limit}")
    public R pageBanner(@PathVariable("page") Long page,
                        @PathVariable("limit") Long limit){
        Page<CrmBanner> pages = new Page<>(page,limit);
        crmBannerService.page(pages,null);
        return R.ok().data("items",pages.getRecords()).data("total",pages.getTotal());
    }

    @GetMapping("get/{id}")
    public R get(@PathVariable("id")String id){
        CrmBanner byId = crmBannerService.getById(id);
        return R.ok().data("item",byId);
    }

    @PostMapping("addBanner")
    public R addBanner(@RequestBody CrmBanner crmBanner){
        crmBannerService.save(crmBanner);
        return R.ok();
    }

    @PostMapping("update")
    public R update(@RequestBody CrmBanner crmBanner){
        crmBannerService.updateById(crmBanner);
        return R.ok();
    }

    @DeleteMapping("remove/{id}")
    public R delete(@PathVariable("id") String id){
        crmBannerService.removeById(id);
        return R.ok();
    }
}

